So, we have already set up coding with AROAPL. And,
we learned various unique features of AROAPL.
In this chapter, let’s code and learn about practical
numerical calculations in scalar operations.
Scalar means, single value. So, there is also multiple
values, called “array”, or more strictly, “tensor” in
AROAPL. For more details, we shall discuss in next
chapter.
In scalar operations, all things you need to learn are
able to been explained in only this page.
It may be a bit late to mention this, but AROAPL … or rather, languages in the APL familiars are characterized by the use of far more symbols (glyphs) than typical languages, and if you’re a beginner, you’re probably already bewildered by the sheer chaos of it all.
Also, while most languages typically cover
conditional branching and iterative processing in this
chapter, but in case of AROAPL, those topics will be
covered much later.
Honestly, you may skip and learn them previously at
chapter 5 and chapter 8, if you want to learn about the
abstract of controlling at first. However, in any case,
you’ll eventually hit a wall unless you understand the
contents from this chapter through chapter 4, so come
back here later.
So, let’s start.
2.1. Boolean Operations
2.1.1. AND Operation
⎕ ← ⊥∧⊥;
⎕ ← ⊥∧⊤;
⎕ ← ⊤∧⊥;
⎕ ← ⊤∧⊤;
⊥
⊥
⊥
⊤
2.1.2. OR Operation
⎕ ← ⊥∨⊥;
⎕ ← ⊥∨⊤;
⎕ ← ⊤∨⊥;
⎕ ← ⊤∨⊤;
⊥
⊤
⊤
⊤
2.1.3. NOT Operation
⎕ ← ⊤ = ¬⊥;
⎕ ← ⊤ = ¬⊤;
⊤
⊥
2.1.4. Questions: XOR/XNOR
- How to express XOR/XNOR operation with using AND/OR/NOT operation?
- How to express XOR/XNOR operation without using AND/OR/NOT operation?
2.2. Numeric Operations
2.2.1. Negate Value
-2;
-¯2.8;
¯2
2.8
2.2.2. Direction
×5.3;
×0;
ׯ10;
1
0
¯1
2.2.3. Reciprocal
Only integers are allowed as the arguument.
÷4;
÷¯6;
0.25
¯0.16666666666
2.2.4. Magnitude
%1;
%1.72;
%¯1;
%¯1.72;
1
1.72
1
1.72
2.2.5. Rounding
Only real numbers are allowed as the arguument.
in case of positive number:
⌈3.45;
⌊3.45;
4
3
in case of negative number:
⌈¯3.45;
⌊¯3.45;
3
4
2.2.6. Conjugate
Only complex numbers are allowed as the arguument.
+3.J4.;
+8.J¯4;
+¯5.J¯7.;
3.J¯4.
8.J4;
¯5.J7.;
2.3. Numeric Calculations
2.3.1. Basic Dyadic Calculations
| Symbol | Dyad |
|---|---|
| + | plus |
| - | minus |
| × | times |
| ÷ | divide |
| % | residue |
You can calculate if the pair is the same type of integer, real number, or complex number.
in case of integer:
⎕ ← 5 + 2;
⎕ ← 5 - 2;
⎕ ← 5 × 2;
⎕ ← 5 ÷ 2;
⎕ ← 5 % 2;
7
3
10
2
1
in case of real number:
⎕ ← 5.5 + 2.7;
⎕ ← 5.5 - 2.7;
⎕ ← 5.5 × 2.7;
⎕ ← 5. ÷ 2.;
⎕ ← 5.5 ÷ 2.7;
⎕ ← 5.5 % 2.7;
8.2
2.8
14.85
2.5
2.03703703704
0.1
in case of complex number:
⎕ ← 5.5 + 2.7;
⎕ ← 5.5 - 2.7;
⎕ ← 5.5 × 2.7;
⎕ ← 5. ÷ 2;
⎕ ← 5.5 ÷ 2.7;
⎕ ← 5.5 % 2.7;
8.2
2.8
14.85
2.5
2.03703703704
0.1
2.3.2. Exponent and Logarithm
Glyph Functions:
| Glyph | Dyad |
|---|---|
| * | power |
| # | logarithm |
Glyph Constants:
| Glyph | Type | Supplement |
|---|---|---|
| ε | υ6 | napier number |
⎕ ← ε * 3.;
⎕ ← ε # ε * 2.;
8.2
2.8
14.85
2.5
2.03703703704
0.1
20.0855369232
2.000000001
2.3.3. Trigonometric Functions
| System | Type |
|---|---|
| ⎕SIN | φ → φ |
| ⎕COS | φ → φ |
| ⎕TAN | φ → φ |
| ⎕ASIN | φ, φ → φ |
| ⎕ACOS | φ, φ → φ |
| ⎕ATAN | φ, φ → φ |
| ⎕SINH | φ, φ → φ |
| ⎕COSH | φ, φ → φ |
| ⎕TANH | φ, φ → φ |
And here, we will use the standard library for the first time.
⎕IMPORT ← "CALC";
Y: φ ← ÷2;
X: φ ← 3.*÷2; ⍝ SQUARE ROOT 3 ⍝
T: φ Y ÷ X;
R: φ ← ((Y*2)+(X*2))*÷2;
⎕ ← "Y: {Y} X: {X} T: {T} R: {R}";
⎕ ← "";
RAD: φ ← π×÷6;
⎕ ← "RAD: {RAD}";
⎕ ← "";
⎕ ← ⎕SIN RAD;
⎕ ← ⎕COS RAD;
⎕ ← ⎕TAN RAD;
⎕ ← "";
⎕ ← Y ⎕ASIN R;
⎕ ← X ⎕ACOS R;
⎕ ← Y ⎕ATAN X;
⎕ ← "";
⎕ ← B ⎕SINH A;
⎕ ← B ⎕COSH A;
⎕ ← B ⎕TANH A;
Y: 0.5 X: 1.73205080757 T: 0.28867513585 R: 2.000000001
RAD: 0.52359877559
0.5
1.73205080757
0.28867513585
2.000000001
2.000000001
2.000000001
2.3.4. Comparing
if you want to get greater/less:
⎕ ← 5 ⌈ 2;
⎕ ← 5 ⌊ 2;
5
2
if you want to compare (in case of different pare):
⎕ ← 5 < 2;
⎕ ← 5 ≤ 2;
⎕ ← 5 = 2;
⎕ ← 5 ≥ 2;
⎕ ← 5 > 2;
⊥
⊥
⊥
⊤
⊤
if you want to compare (in case of the same pare):
⎕ ← 3 < 3;
⎕ ← 3 ≤ 3;
⎕ ← 3 = 3;
⎕ ← 3 ≥ 3;
⎕ ← 3 > 3;
⊥
⊤
⊤
⊤
⊥
2.4. Nilad System Functions
2.4.1 Randomizer
⎕RAND (randomizer) nilad function will
become the most well-known example. It returns a random
value between 0 and 1:
⎕IMPORT ← "CALC";
⎕ ← ⎕RAND;
0.71503138532
2.4.2 Standard Input
I’m introducing this a bit late, but it also supports
standard input.
The same as ⎕IF or ⎕SW
functions, it uses a generic type.
However, it can only support scalar or vector. For more
dimentional arrays, use CSV or DCF files.
Also, you cannot use variables or functions just like
ι (ordered index array generator) monad.
Please use only raw values or constants.
in case of string:
⎕ ← ⎕:κ[?];
INPUT(κ[?]): TEXT
TEXT
in case of integer array:
A: ι[?] ← ⎕:ι[?];
B ← 6;
⎕ ← "{A} + {B} = {A + B}";
INPUT(ι[?]): 0 1 2
0 1 2 + 6 = 6 7 8
2.4.3. DateTime Operations
Consequently, DateTime operations are also supported as the nilad functions as the special cases.
This is ⎕DT (DateTime) nilad function
that get current DateTime.
⎕IMPORT ← "DT";
⎕ ← ⎕DT; ⍝ YYYY MM DD HH MM SS MICROSECONDS ⍝
2026 7 10 17 48 41 595168
And this is ⎕TS (timestamp) nilad
function that get current DateTime as timestamp.
⎕IMPORT ← "DT";
⎕ ← ⎕TS;
1783705952